package com.dengc.service.impl;

import com.dengc.mapper.SysRoleMapper;
import com.dengc.pojo.SysRole;
import com.dengc.service.SysRoleService;
import com.dengc.utils.Contants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("SysRoleService")
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;


    @Override
    public List<SysRole> getAllRoles() {
        return sysRoleMapper.getSysRoleByCondition(new SysRole());
    }

    //实现分页显示功能
    @Override
    public PageInfo<SysRole> getSysRoleByPage(SysRole sysRole, int pageNum) {
        //开启分页
        PageHelper.startPage(pageNum, Contants.PAGESIZE);
        //分页好的数据保存起来
        List<SysRole> list = sysRoleMapper.getSysRoleByCondition(sysRole);
        return new PageInfo<>(list);
    }

    @Override
    public int upDateRole(SysRole sysRole) {
        return sysRoleMapper.upDateRole(sysRole);
    }

    //根据id查询角色信息
    @Override
    public SysRole getIdSysRole(Integer id) {
        SysRole sysRole = new SysRole();
        sysRole.setId(id);
        List<SysRole> list = sysRoleMapper.getSysRoleByCondition(sysRole);
        return list.get(0);
    }

    //添加角色实现
    @Override
    public int addRole(SysRole sysRole) {
        return sysRoleMapper.addRole(sysRole);
    }

    //删除角色实现
    @Override
    public int deleteRole(Integer id) {
        return sysRoleMapper.deleteRole(id);
    }

}
